package android.slc.appbase.ui

import android.slc.box.core.launcher.StageLauncherConfigImpl
import javafx.scene.image.Image
import javafx.stage.Modality
import javafx.stage.Stage
import javafx.stage.StageStyle

open class AppStageLauncherConfigSimple : StageLauncherConfigImpl(), AppStageLauncherConfig {

    companion object {

        fun newInstance(): AppStageLauncherConfig {
            return AppStageLauncherConfigSimple()
        }

        fun newInstanceOwnerFrom(): AppStageLauncherConfig {
            return AppStageLauncherConfigSimple().apply {
                this.ownerMode = true
                this.modality = Modality.WINDOW_MODAL
            }
        }

        fun newInstanceUndecorated(): AppStageLauncherConfig {
            return AppStageLauncherConfigSimple().apply {
                this.stageStyle = StageStyle.UNDECORATED
            }
        }

    }

    var stageStyle: StageStyle? = null

    var ownerMode: Boolean = false

    var modality: Modality? = null

    override fun initStage(ownerStage: Stage?, currentStage: Stage) {
        super<AppStageLauncherConfig>.initStage(ownerStage, currentStage)
        super<StageLauncherConfigImpl>.initStage(ownerStage, currentStage)
        currentStage.icons.add(Image("images/icon.png"))
        applyParams(ownerStage, currentStage)
    }

    protected open fun applyParams(ownerStage: Stage?, currentStage: Stage) {
        stageStyle?.let {
            currentStage.initStyle(it)
        }
        if (ownerMode) {
            currentStage.initOwner(ownerStage)
        }
        modality?.let {
            currentStage.initModality(it)
        }
    }

    override fun setStageParamsRunLast(currentStage: Stage) {
        super<StageLauncherConfigImpl>.setStageParamsRunLast(currentStage)
        super<AppStageLauncherConfig>.setStageParamsRunLast(currentStage)
        currentStage.centerOnScreen()
    }

    override fun createCurrentStage(): Stage {
        return Stage()
    }

}
